package calao.storage.bdb;

import com.sleepycat.bind.tuple.TupleOutput;
import com.sleepycat.je.DatabaseException;

import calao.storage.DataBinding;
import calao.storage.DataWriter;

public class TupleDataWriter 
extends DataWriter 
{
	
	final TupleOutput output;
	
	TupleDataWriter(TupleOutput output)
	{
		this.output = output;
	}

	@Override
	public void write(int value) 
	{
		output.writePackedInt(value);
	}

	@Override
	public void write(long value) 
	{
		output.writeLong(value);
	}

	@Override
	public void write(double value) 
	{
		output.writeDouble(value);
	}

	@Override
	public void write(String value) 
	{
		output.writeString(value);
	}
	
	@Override
	public void writeBindingName(DataBinding binding)
	{
		try {
			output.writePackedInt(BdbStorage.envRegistry.getId(binding));
		}
		catch (DatabaseException e) {
			throw new RuntimeException(e);
		}
	}

	@Override
	public void write(boolean value) 
	{
		output.writeBoolean(value);
	}

}
